package com.crm.service.home.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.crm.model.common.dtos.ResponseResult;
import com.crm.model.crm.businessOpportunities.pojo.CustomInfo;
import com.crm.model.home.vo.BasicDataVo;
import com.crm.service.crm.businessOpportunities.mapper.CustomInfoMapper;
import com.crm.service.home.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Service
public class HomeServiceImpl implements HomeService {
    @Autowired
    private CustomInfoMapper customInfoMapper;

    /**
     * 基础数据查询
     *
     * @param beginTime
     * @param endTime
     * @return
     */
    @Override
    public ResponseResult basicData(LocalDate beginTime, LocalDate endTime) {
        BasicDataVo basicDataVo = new BasicDataVo();

        LambdaQueryWrapper<CustomInfo> lqw = new LambdaQueryWrapper<CustomInfo>()
                .le(CustomInfo::getCreateTime, endTime)
                .ge(CustomInfo::getCreateTime, beginTime);
        basicDataVo.setCustomerNumber(customInfoMapper.selectCount(lqw));
        //TODO:魔法数字
        basicDataVo.setBusinessOpportunitiesNumber(customInfoMapper.selectCount(lqw.eq(CustomInfo::getStatus,3)));
        //TODO:线索统计和销售额统计
        basicDataVo.setCluesNumber(100);
        basicDataVo.setSalesVolume(21000.00);
        return ResponseResult.okResult(basicDataVo);
    }
}
